﻿unit ETypeEditFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JvExControls, JvXPCore, JvXPButtons, ExtCtrls, StdCtrls, Mask, DB,
  DBCtrlsEh, CheckLst, FIBQuery, pFIBCacheQueries;

type
  TETypeEditForm = class(TForm)
    Panel1: TPanel;
    JvXPButton1: TJvXPButton;
    JvXPButton2: TJvXPButton;
    Label1: TLabel;
    EName: TDBEditEh;
    Grants: TCheckListBox;
    DBCheckBoxEh1: TDBCheckBoxEh;
    DBCheckBoxEh2: TDBCheckBoxEh;
    GroupBox1: TGroupBox;
    Derect: TDBComboBoxEh;
    procedure JvXPButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure JvXPButton2Click(Sender: TObject);
  private
    procedure GetENext;
    procedure SetENext;
  public
    { Public declarations }
  end;

var
  ETypeEditForm: TETypeEditForm;

implementation
 uses  ETypeFrm, DModule;

{$R *.dfm}

procedure TETypeEditForm.JvXPButton1Click(Sender: TObject);
 var DS: TDataSet;
begin
 DS:=EName.DataSource.DataSet;
 DS.Edit;
 GetENext;
 DS.Post;
end;

procedure TETypeEditForm.JvXPButton2Click(Sender: TObject);
begin
 EName.DataSource.DataSet.Cancel;
 ModalResult:=mrCancel;
end;

procedure TETypeEditForm.FormCreate(Sender: TObject);
begin
 SetENext;
end;

procedure TETypeEditForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 case Key of
  VK_ESCAPE: JvXPButton2Click(nil);
 end;
end;

procedure TETypeEditForm.GetENext;
 var S: string;
     i: integer;
     DS: TDataSet;
begin
 DS:=EName.DataSource.DataSet;
 S:='';
 for i:=0 to Grants.Count - 1 do
  if Grants.Checked[i] then
    S:=S+'1' else S:=S+'0';
 DS.FieldByName('Owner').AsString:=S;
end;

procedure TETypeEditForm.SetENext;
 var S: string;
     i: integer;
     DS: TDataSet;
begin
 DS:=EName.DataSource.DataSet;
 if DS.IsEmpty then Exit;
 S:=DS.FieldByName('Owner').AsString;
 for i:=0 to Grants.Items.Count - 1 do
  Grants.Checked[i]:=Copy(S,i+1,1)='1';
end;

end.
